package com.klikmee.sms.services.chat.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Set;

/**
 * The persistent class for the Group database table.
 * 
 */
@Entity
@Table(name = "groups")
@NamedQueries({ @NamedQuery(name = "Group.findAll", query = "SELECT g FROM Group g"), 
@NamedQuery(name = "Group.findAllGroupsForAgent", query = "SELECT g FROM Group g INNER JOIN g.agentGroups ag WHERE ag.agent = :agent"),
@NamedQuery(name = "Group.findAdministratorGroupsForAgent", query = "SELECT g FROM Group g INNER JOIN g.agentGroups ag WHERE ag.agent = :agent AND g.administration = true") })
public class Group implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "GroupID")
	private int groupID;

	@Column(name = "GroupDescription")
	private String groupDescription;

	@Column(name = "GroupName")
	private String groupName;

	@Column(name = "Active")
	private Boolean active;
	
	@Column(name = "Administration")
	private Boolean administration;

	// bi-directional many-to-one association to AgentGroup
	@OneToMany(mappedBy = "group")
	private Set<AgentGroup> agentGroups;

	public Group() {
		this.setActive(Boolean.FALSE);
	}

	public int getGroupID() {
		return this.groupID;
	}

	public void setGroupID(int groupID) {
		this.groupID = groupID;
	}

	public String getGroupDescription() {
		return this.groupDescription;
	}

	public void setGroupDescription(String groupDescription) {
		this.groupDescription = groupDescription;
	}

	public String getGroupName() {
		return this.groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public Set<AgentGroup> getAgentGroups() {
		return this.agentGroups;
	}

	public void setAgentGroups(Set<AgentGroup> agentGroups) {
		this.agentGroups = agentGroups;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public Boolean getActive() {
		return active;
	}
	
	public void setAdministration(Boolean administration) {
		this.administration = administration;
	}

	public Boolean getAdministration() {
		return administration;
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null) {
			return false;
		}

		else {
			Group otherGroup = (Group) obj;
			if (this.groupID == otherGroup.getGroupID()) {
				return true;
			} else {
				return false;
			}
		}
	}
}